import axios from 'axios'
import { takeEvery, put } from 'redux-saga/effects'
import { filter_product, filter_product_success } from '../actions/filter'
import { API } from '../../config'

function* handleFilterProduct (action) {
	const {data} = yield axios.post(`${API}/products/filter`, action.payload)
	yield put(filter_product_success({skip: action.payload.skip, ...data}))
}

export default function* filterSaga () {
	yield takeEvery(filter_product, handleFilterProduct)
}